<?php

class M_master_produk extends CI_Model {

	function __construct()
	{
		$this->load->database();
	}
	
	// --------------------------------------------------------------------

      /** 
       * function Produk_Po()       	   
       * @param $form_data - array
	   *
	   * function SimpanProduk_po()       	   
       * @param $form_data - array
	   *
	   * function EditProduk_po()       	   
       * @param $form_data - array
	   *
	   * function HapusProduk_po()       	   
       * @param $form_data - array
	   *
	   * function SimpanProduk()       	   
       * @param $form_data - array
	   *
       * @return Bool - TRUE or FALSE
       */
	    
	function Produk($proses,$param,$form_data)
	{
		/*Total Kondisi Where Query*/
		$tot_param 	= sizeof($param);
		
		/*Set Default Data*/
		$rows_array = 0;
		$kondisi	= "where";
		
		switch ($proses){
		case 1: /*Insert*/
			break;
		case 2: /*Update*/
			break;		
		case 3: /*Delete*/
			break;	
		case 4: /*Select*/
			/*Set Kondisi Where Query*/
			if($tot_param > 0){
				foreach($param as $value)
				{
					/*----------------------
					- Nambah Parametter Kondisi Where Tinggal Di Tambah di Casenya
					------------------------*/
					++$rows_array;
					switch ($rows_array){
					case 1: /*ProKode*/
						if(!empty($value)){
							$kondisi=$kondisi."prokode='".$value."'";
						}
					
					case 2: /*Nama*/
						if(!empty($value)){
							$kondisi=$kondisi." ucase(nama) like'".$value."%'";
						}
					
					}
				}
				/*End Statement SQL*/
				$kondisi=$kondisi.";";				
				$sql = "SELECT * FROM PRODUK ".$kondisi;
			}
			else{
				/* Tanpa Kondisi */
				$sql = "SELECT * FROM PRODUK ";
			}
			
			//return $this->db->query($sql)->result();	
			$query = $this->db->query($sql);			
			if ($query->num_rows() > 0){
				foreach( $query->result() as $data ){
					$produk[] = $data;
				}
				return $produk;
					
			}					
			
		}
		return FALSE;			
		break;						
	}
	
	function SaveForm($form_data)
	{
		$this->db->insert('purchasing', $form_data);
		
		if ($this->db->affected_rows() == '1')
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
}
?>